<template>
  <p-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">

        <p-row>
		  <p-col  :span="24">
			<p-form-item label="工单下发时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'outsourcingTime', validatorRules.outsourcingTime]" placeholder="请输入工单下发时间"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="产品类别" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['type', validatorRules.type]" :trigger-change="true" dictCode="pmc_mtype" placeholder="请选择产品类别"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="工单类别" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'outsourcingType', validatorRules.outsourcingType]" placeholder="请输入工单类别"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="工单编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'mobillno', validatorRules.mobillno]" placeholder="请输入工单编号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="供应商编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="basic-business"
						v-decorator="['custno', validatorRules.custno]"
						:trigger-change="true"
						org-fields="supno,supname"
						dest-fields="custno,custname"
						code="ba_supinfo"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="供应商名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'custname', validatorRules.custname]" placeholder="请输入供应商名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="采购订单" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'purchaseOrder', validatorRules.purchaseOrder]" placeholder="请输入采购订单"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="物料编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="basic-business"
						v-decorator="['mcode', validatorRules.mcode]"
						:trigger-change="true"
						org-fields="id,mcode,mname,sprc,mexplain,units,mtypename"
						dest-fields="mid,mcode,mname,unit,sprc,units,"
						code="wms_cpinfo"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="物料描述" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'mexplain', validatorRules.mexplain]" placeholder="请输入物料描述"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="物料描述" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'mdescription', validatorRules.mdescription]" placeholder="请输入物料描述"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="计划数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'outsourcingQuantity', validatorRules.outsourcingQuantity]" placeholder="请输入计划数量"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="产品BOM版本号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'outsourcingBomversions', validatorRules.outsourcingBomversions]" placeholder="请输入产品BOM版本号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="起始SN/PN" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'outsourcingStartsn', validatorRules.outsourcingStartsn]" placeholder="请输入起始SN/PN"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="终止SN/PN" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'outsourcingTerminationsn', validatorRules.outsourcingTerminationsn]" placeholder="请输入终止SN/PN"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="工单状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-switch  placeholder="String" v-decorator="['outsourcingState']" field="outsourcingState" dictCode="" @callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="产品BOM更新时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择产品BOM更新时间" v-decorator="[ 'outsourcingBomtime', validatorRules.outsourcingBomtime]" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'remark', validatorRules.remark]" placeholder="请输入备注"></p-input>
			</p-form-item>
		  </p-col>
        </p-row>


      </p-form>
    </p-spin>
  </p-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import fSwitch from '@/components/switch'
  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"

  export default {
    name: "MesMfOutsourcingWorkModal",
    mixins: [SubmitOnchangMixin],
    components: {
      JDate,
      JDictSelectTag,
      fSwitch,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width: 800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          outsourcingTime: {rules: [
          ]},
          type: {rules: [
          ]},
          outsourcingType: {rules: [
          ]},
          mobillno: {rules: [
          ]},
          custno: {rules: [
          ]},
          custname: {rules: [
          ]},
          purchaseOrder: {rules: [
          ]},
          mcode: {rules: [
            {required: true, message: '请输入物料编码!'},
          ]},
          mexplain: {rules: [
          ]},
          mdescription: {rules: [
          ]},
          outsourcingQuantity: {rules: [
          ]},
          outsourcingBomversions: {rules: [
          ]},
          outsourcingStartsn: {rules: [
          ]},
          outsourcingTerminationsn: {rules: [
          ]},
          outsourcingState: {rules: [
          ]},
          outsourcingBomtime: {rules: [
          ]},
          remark: {rules: [
          ]},
        },
        url: {
          add: '/mes-manufacture/auto/mesMfOutsourcingWork/add',
          edit: '/mes-manufacture/auto/mesMfOutsourcingWork/edit',
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },

      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'outsourcingTime','type','outsourcingType','mobillno','custno','custname','purchaseOrder','mcode','mexplain','mdescription','outsourcingQuantity','outsourcingBomversions','outsourcingStartsn','outsourcingTerminationsn','outsourcingState','outsourcingBomtime','createBy','createTime','updateBy','updateTime','remark'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
              that.confirmLoading = true;
              let httpurl = '';
              let method = '';
              let formData = Object.assign(this.model, values);
              this.formData = Object.assign(this.model, values);
              //新增触发
              if(!this.model.id){
                httpurl+=this.url.add;
                method = 'post';
                if(this.EnhanceJS.afterAdd){
                  //新增之前
                  let Obj = eval(this.EnhanceJS.afterAdd)
                  new Obj(this)
                }else{
                  console.log("表单提交数据",formData)
                  that.modalFrom(httpurl,formData,method)
                }
              }else{
                //编辑触发
                httpurl+=this.url.edit;
                method = 'put';
                if(this.EnhanceJS.afterEdit){
                 //编辑之前
                  let Obj = eval(this.EnhanceJS.afterEdit)
                  new Obj(this)
                }else{
                  console.log("表单提交数据",formData)
                  that.modalFrom(httpurl,formData,method)
                }
              }
          }

        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'outsourcingTime','type','outsourcingType','mobillno','custno','custname','purchaseOrder','mcode','mexplain','mdescription','outsourcingQuantity','outsourcingBomversions','outsourcingStartsn','outsourcingTerminationsn','outsourcingState','outsourcingBomtime','createBy','createTime','updateBy','updateTime','remark'))
      },


    }
  }
</script>
